package servlet;

import domain.Emp;
import service.EmpAddServiceImp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class EmpAddServlet extends HttpServlet {
    private EmpAddServiceImp empAddServiceImp=new EmpAddServiceImp();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取到请求的参数
        //获取到员工的姓名
        String ename =request.getParameter("ename");
        //获取到员工的年龄
        String age = request.getParameter("age");
        //获取到员工的性别
        String sex=request.getParameter("sex");
        //获取到员工的工资
        String sal = request.getParameter("sal");
        //获取到员工的生日
        String birthday = request.getParameter("birthday");
        //获取到员工入职时间
        String edate = request.getParameter("edate");
        Emp emp=new Emp();
        //设置emp的信息
        emp.setId(null);
        emp.setEname(ename);
        emp.setAge(Integer.parseInt(age));
        emp.setSex(sex);
        emp.setSal(Double.parseDouble(sal));
        emp.setBirthday(birthday);
        emp.setEdate(edate);
        empAddServiceImp.addEmp(emp);
        request.getRequestDispatcher("/empListServlet").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       doPost(request,response);
    }
}
